package com.ruoyi.web.controller.laiqianba.merchant;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;


import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.laiqianba.service.IAddressInfoService;
import com.ruoyi.laiqianba.service.IAdminHttpService;
import com.ruoyi.merchant.service.IMerchantBaseInfoService;
import com.ruoyi.merchant.service.IMerchantCheckInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.MerchantCheckInfo;
import com.ruoyi.web.wrapper.MerchantCheckInfoWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 撞库测试Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/merchant/check")
public class MerchantCheckInfoController extends BaseController
{
    @Autowired
    private IMerchantCheckInfoService merchantCheckInfoService;
    @Autowired
    private IMerchantBaseInfoService merchantBaseInfoService;
    @Autowired
    IAdminHttpService adminHttpService;
    @Autowired
    IAddressInfoService addressInfoService;

    @GetMapping("/extData")
    public AjaxResult extData()
    {
        JSONObject returnData = new JSONObject();
        returnData.put("infoIdList", merchantBaseInfoService.getChantBaseInfoId());
        returnData.put("cityList", addressInfoService.getCtiy());
        return AjaxResult.success(returnData);
    }

    /**
     * 查询撞库测试列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantCheckInfo merchantCheckInfo)
    {
        startPage();
        List<Map<String, Object>> list = merchantCheckInfoService.selectMerchantCheckInfoMapList(merchantCheckInfo);
        list = new MerchantCheckInfoWrapper(list).wrap();
        return getDataTable(list);
    }

    /**
     * 导出撞库测试列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:export')")
    @Log(title = "撞库测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantCheckInfo merchantCheckInfo)
    {
        List<MerchantCheckInfo> list = merchantCheckInfoService.selectMerchantCheckInfoList(merchantCheckInfo);
        ExcelUtil<MerchantCheckInfo> util = new ExcelUtil<MerchantCheckInfo>(MerchantCheckInfo.class);
        util.exportExcel(response, list, "撞库测试数据");
    }

    /**
     * 获取撞库测试详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(merchantCheckInfoService.selectMerchantCheckInfoById(id));
    }

    /**
     * 新增撞库测试
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:add')")
    @Log(title = "撞库测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantCheckInfo merchantCheckInfo)
    {
        return adminHttpService.merchantcheckPush(merchantCheckInfo);
    }

    /**
     * 修改撞库测试
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:edit')")
    @Log(title = "撞库测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantCheckInfo merchantCheckInfo)
    {
        return toAjax(merchantCheckInfoService.updateMerchantCheckInfo(merchantCheckInfo));
    }

    /**
     * 删除撞库测试
     */
    @PreAuthorize("@ss.hasPermi('merchant:check:remove')")
    @Log(title = "撞库测试", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantCheckInfoService.deleteMerchantCheckInfoByIds(ids));
    }

}
